export default {
    state: {
    	username:"foo",
    	age:18,
    	count: 1,
    	todos: [{
    			id: 1,
    			text: '我是内容一',
    			done: true
    		},
    		{
    			id: 2,
    			text: '我是内容二',
    			done: false
    		}
    	]
    },
    getters: {
    	doneTodos: (state:any) => {
    		return state.todos.filter((todo:any) => todo.done)
    	},
    	doneTodosCount: (state:any, getters:any) => {
    		//state ：可以访问数据
    		//getters：访问其他函数，等同于 store.getters
    		return getters.doneTodos.length
    	},
    	getTodoById: (state:any) => (id:any) => {
    		return state.todos.filter((todo:any) => todo.id === id)
    	}
    },
    mutations: {
    	add(state:any,n:any) {
    		// 变更状态
    		state.count += n
    	}
    },
    actions:{
    	addCountAction ({commit,state }:any,n:any) {
    		setTimeout(function () {
    			commit('add',n)
    		}, 2000)
    	}
    }
}